/*
 * @Descripttion: 表格汇总的混入文件
 * @Author: caijj
 * @Date: 2020-12-28 11:25:32
 * @LastEditors: ququ
 * @LastEditTime: 2021-04-02 11:09:15
 */
export default {
  data() {
    return {
      showSummary: false, // 动态展示汇总属性
      summaries: [] // 异步请求返回的数组
    };
  },
  methods: {
    getSummaries(params) {
      const { columns } = params;
      const sums = [];
      if (this.summaries === null || this.summaries === []) return [];
      const isNotEmpty = Object.keys(this.summaries).length !== 0;
      columns.forEach((column, index) => {
        const { property } = column;
        if (index === 0) {
          sums[index] = '汇总';
          return;
        }
        sums[index] = isNotEmpty ? this.summaries[property] : '-';
      });
      return sums;
    },
    /* 报表汇总接口 */
    getRetailDetailsTotal(formData, url) {
      // const api = flag ? getDetailTotal : getDetailsTotal;
      url(formData)
        .then(({ data }) => {
          data && data.length > 0 && data.length === 1 ? (this.summaries = data[0]) : (this.summaries = data || []);
          this.showSummary = true;
        })
        .catch(() => {
          this.showSummary = false;
        });
    }
  }
};
